# 导入selenium库中的webdriver模块，用于控制浏览器
import pyperclip
from selenium import webdriver
import pyautogui
import time
import base64
import requests
import json
import os


pyautogui.FAILSAFE = False

# 百度举报

# http://106.75.35.45:5000/project/1/job/dashboard
# 创建一个Chrome浏览器实例
driver = webdriver.Chrome()

# 打开谷歌浏览器，并访问指定的网址
url = "https://www.baidu.com/s?wd=谷歌浏览器"
# url = "http://jubao.baidu.com/jubao/accu/?surl=http%3A%2F%2Fwww.baidu.com%2Fbaidu.php%3Furl%3D060000KKXYb9K48fSYBo66MAUaArmEcR-tdKqwWeF0LvJL3_Xud_pUZH4N7UTxuc6zs4isL-kkHufJYh7OUMDM4phti0iQR-4lwCwQI110EclDlA7bDdXBdT_szfYUUDR3m1HNhUgefNiskjnZIQHMDttWw-L1olx1PfXmGru5FimeJGAN1wDugxn4grNn4xwhRnaW-xoAVg85MbfoeJpWuY8kZ4.DD_NR2Ar5Od66lrAlOzWxh8Iswc6WHG69Jxw8E86dtX5H1ekl4Mpyn-MHdSglZ3_NqXdrWeOFWGLu5ZWdOfSEljAqHReiM-kl-9h9molple7.U1Yk0ZDq8TB3lriEsnjAqsKspynqn0KY5yIEUvI_uyPCThqVufKGUHYznWR0u1dEugK1n0KdpHdBmy-bIfKspyfqPfKWpyfqP100UgfqnH0krNtknjDLg1nknWKxn1DYr7tznjRkg1nvnjD0pvbqn0KzIjYvrHT0mhbqnHR3g1csP7tdnjn0UynqnH0krNtknjDLg1Dsn-tknjFxnW0dnNts0Z7spyfqn0Kkmv-b5H00ThIYmyTqn0K9mWYsg100ugFM5Hc0TZ0qn1RzrHR1rHfdn0K8IM0qna3snj0snj0sn0KVIZ0qn0KbuAqs5H00ThCqnfKbugmqTAn0uMfqn0KspjYs0Aq15H00mMTqnH00UMfqn0K1XWY0mgPxpywW5gK1QyIlpZ940A-bm1dcHbD0TA9YXHY0IA7zuvNY5Hm1g1KxnHR10ZwdT1YknWmvPW6vnWcvP10YnH6Yn10zrfKzug7Y5HDLnH64n1fYnjn1nH60Tv-b5yn4nW9Bn1F9nj0snWT1Pjf0mLPV5RmkPHuKP1RsPjcLfHKjPRn0mynqnfKsUWYs0Z7VIjYs0Z7VT1Ys0Aw-I7qWTADqn0KlIjYs0AdWgvuzUvYqn7tsg1Kxn7tsg100uA78IyF-gLK_my4GuZnqn7tsg1nknjc4njnkg1nknjc4njnkg1Kxn0Ksmgwxuhk9u1Ys0AwWpyfqn0K-IA-b5iYk0A71TAPW5H00IgKGUhPW5H00Tydh5H00uhPdIjYs0A-1mvsqn0K9uAu_myTqnfK_uhnqn0KbmvPb5HKawbuKrjTLPWRvPRPafW9AnRcLnYRYf1F7fWT4n1D1xj00IZF9uARqn0KBuA-b5RcdnYfLfHRswWmznjDsPWcdnRfvfbR4nHcLnDnkPRcL0AqW5HD0mMfqn0KEmgwL5H00ULfqnfKETMKY5HcWnanvc1DWn1DdnH64njn3nznLPznLPz3snj0snj0Wnznkc10WQinsQW01rHRdninkQW0snj0snankc10Wna3snj0snj0Wnansc10Wnansc100mh78pv7Wm1Y1nBn1nBn1nBnzP0KkgLmqna34rNtsQW0sg108njKxna34rNtsQW63g1Kxna33r7ts0AF1gLKzUvwGujYs0ZFEpyu_myTqn0KWIWY0pgPxmLK95H00mL0qn0K-TLfqn0KkuLIb5H00UL0k5H00TZ0Y5H00mLFW5HDLnjcs&token=3E9FA1569105D763C523C721AF5A0C21&title=%E8%B0%B7%26%E6%AD%8C%E6%B5%8F%E8%A7%88%E5%99%A8%E4%B8%8B%E8%BD%BD-%E9%AB%98%E9%80%9F%E6%99%BA%E8%83%BD%E6%B5%8F%E8%A7%88%E5%99%A8-%E6%AD%A3%E7%89%88%E5%85%8D%E8%B4%B9%E4%B8%8B%E8%BD%BD!&q=%E8%B0%B7%E6%AD%8C%E6%B5%8F%E8%A7%88%E5%99%A8&has_gw=0&has_v=0"
# 设置要添加的cookie
cookies = {
    "PSTM": "1697096844",
    "BIDUPSID": "F94B177601628A5D804C4599953A73C1",
    "MSA_WH": "394_848",
    "BD_UPN": "12314753",
    "MCITY": "-194%3A",
    "BAIDUID": "5F28C4F143D4114F7A2ACC3213AF2E7B:FG=1",
    "BDUSS": "S1BdTkwZk1KMjFhYlRlaGZ3Un5rODViLXJOTkwzekJ-SnNGWGc4Z2tycjIwMWRtSVFBQUFBJCQAAAAAAAAAAAEAAAC3Tyl8yq68q7bIz~nVxcquAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZGMGb2RjBmc",
    "BDUSS_BFESS": "S1BdTkwZk1KMjFhYlRlaGZ3Un5rODViLXJOTkwzekJ-SnNGWGc4Z2tycjIwMWRtSVFBQUFBJCQAAAAAAAAAAAEAAAC3Tyl8yq68q7bIz~nVxcquAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZGMGb2RjBmc",
    "H_PS_PSSID": "60277_60297_60325_60337",
    "H_WISE_SIDS": "60277_60297_60325_60337",
    "H_WISE_SIDS_BFESS": "60277_60297_60325_60337",
    "BDORZ": "B490B5EBF6F3CD402E515D22BCDA1598",
    "BAIDUID_BFESS": "5F28C4F143D4114F7A2ACC3213AF2E7B:FG=1",
    "delPer": "0",
    "BD_CK_SAM": "1",
    "PSINO": "6",
    "BA_HECTOR": "218500ah2l8g80ah80a484a0bl1if41j77ihg1u",
    "ZFY": "syi9ph8SRs1pvXxWeeUzvyY4PoYqoS:BFqsMoBNuzw3U:C",
    "sugstore": "1",
    "H_PS_645EC": "08a7ZvUumpapDBxIzgoBFRpBSCLPcEeyzkb%2Bsv7kk0QyxzThN7ptWCPXpXs",
    "ab_sr": "1.0.1_ZjcxY2E3ZWI0MzMyZTYwYmMyNmU0MmMxOGQ3ODk5YmZkMWI3ZTMzZjUwMDllY2ZjOTAwNzIwMjdjNmU2NWI5ZTBhNjNmMzQ0NGYzMDFjM2E4OWM3Y2JmZGEzYTgzOGZiMGRjZTgyZWZlYmQwODhhYzM2MzBmMTkzMmUzM2UzMGEwODZjZmEwYWE3ZjQ3MDIzOWM4YTZhODM5YzBiODAzZDMyZTQ0MzkwMTc1MDZiMzQ4MWQwZmIwOWM0MGRiMjUw",
    "RT": "z=1&dm=baidu.com&si=2cd12338-3aab-4e25-814a-5f01d3580be8&ss=lxdzeaux&sl=tk&tt=nfzt&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=8xi4iu"
}

# 使用get方法访问网址，并将cookie添加到浏览器中
driver.get(url)
# 放大
x1, y1 = 890, 30
pyautogui.moveTo(x1, y1, duration=0.5)
pyautogui.click()
time.sleep(1)
# 检查
x1, y1 = 110, 500
pyautogui.moveTo(x1, y1, duration=0.5)
pyautogui.rightClick()
time.sleep(1)
x1, y1 = 120, 900
pyautogui.moveTo(x1, y1, duration=0.5)
pyautogui.click()
time.sleep(1)
# 移动端
x1, y1 = 1410, 222
pyautogui.moveTo(x1, y1, duration=0.5)
pyautogui.click()
time.sleep(1)
# 刷新页面
x1, y1 = 95, 65
pyautogui.moveTo(x1, y1, duration=0.5)
pyautogui.click()
time.sleep(1)

# 给页面添加cookie
for key, value in cookies.items():
    driver.add_cookie({"name": key, "value": value})
time.sleep(2)
driver.get(url)

# 去举报
x1, y1 = 850, 580
pyautogui.moveTo(x1, y1, duration=0.5)
pyautogui.click()
time.sleep(1)
# 点击去举报
x1, y1 = 600, 845
pyautogui.moveTo(x1, y1, duration=0.5)
pyautogui.click()
time.sleep(5)

# 填写举报信息
x1, y1 = 570, 520
pyautogui.moveTo(x1, y1, duration=0.5)
pyautogui.click()
time.sleep(1)

# 鼠标滚动
pyautogui.scroll(-1000)
time.sleep(1)
str = "信息与实际不符"
pyperclip.copy(str)

# 移动到资料填写
time.sleep(2)
x1, y1 = 670, 700
pyautogui.moveTo(x1, y1, duration=0.5)
# 点击
pyautogui.click()
# 粘贴
pyautogui.hotkey('ctrl', 'v')

# 去提交举报
x1, y1 = 690, 970
pyautogui.moveTo(x1, y1, duration=0.5)
pyautogui.click()

time.sleep(160)
exit()
# 执行完成


# 设置鼠标移动到的第一个位置的坐标
x1, y1 = 355, 655

# 设置鼠标移动到的第二个位置的坐标
x2, y2 = 355, 700
time.sleep(30)
exit()

# 将鼠标移动到第一个位置
pyautogui.moveTo(x1, y1, duration=0.5)
# 点击进入举报
pyautogui.click(x2, y2, duration=0.5)

# 选择举报类型
# x, y = 250, 642
# pyautogui.moveTo(x, y, duration=1)
# time.sleep(1)
# pyautogui.click()
# time.sleep(1)

# 输入内容
x, y = 300, 800
str = "信息与实际不符"
pyperclip.copy(str)
# 移动到输入框
pyautogui.moveTo(x, y, duration=0.5)
# 点击
pyautogui.click()
# 粘贴
pyautogui.hotkey('ctrl', 'v')
# 在第一个位置停留1秒
time.sleep(1)

# 鼠标滚动
pyautogui.scroll(-1000)

# 去点击提交
x, y = 120, 730
pyautogui.moveTo(x, y, duration=0.5)
time.sleep(1)
pyautogui.click()
time.sleep(1)

# 在当前鼠标位置执行右键点击
pyautogui.rightClick()
x, y = 140, 705
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)

# 查看元素
x, y = 412, 235
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)

# 查看图片DIV
x, y = 190, 520
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)

# 查看图片
x, y = 460, 600
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)

# 查看图片img
x, y = 530, 605
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)

# 去除不可下载
x, y = 405, 865
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)

# 右键查看图片
x, y = 190, 520
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.rightClick()
time.sleep(1)

# 下载图片
x, y = 250, 570
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)

# 粘贴要存放的位置
str = "C:/Users/Administrator/Desktop/codeimg"
pyperclip.copy(str)
x, y = 480, 60
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)
pyautogui.hotkey('ctrl', 'v')
time.sleep(1)

x, y = 710, 60
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)
# 去保存
x, y = 815, 515
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)

# 关闭查看元素
x, y = 930, 230
pyautogui.moveTo(x, y, duration=0.5)
pyautogui.click()
time.sleep(1)

# 进行接口请求图片
imgpatch = "C:/Users/Administrator/Desktop/codeimg/img.jpg"
# 读取图片文件
with open(imgpatch, 'rb') as image_file:
    encoded_string = base64.b64encode(image_file.read()).decode('utf-8')

# 创建POST请求的数据
data = {
    'token': 'Ky55lPVrj4V8o6K6VQcw8rHRS_TOFPBZqOgDsSM374Y',
    'type': '90007',
    'image': encoded_string
}
# 设置请求头（如果接口需要特定的Content-Type或其他头）
headers = {
    'Content-Type': 'application/json',  # 或者根据接口要求设置为 'application/x-www-form-urlencoded' 或其他
}
# 发送POST请求
response = requests.post('http://api.jfbym.com/api/YmServer/customApi', json=data, headers=headers)
res = json.loads(response.text)
angle_deg = 0
if res['code'] != 10000:
    print('图片识别识别')
    exit()
else:
    # 角度
    print(res)
    angle_deg = res['data']['data']
    os.remove(imgpatch)
# ------------------------------

# 移动到验证码图片处
x, y = 370, 670
pyautogui.moveTo(x, y, duration=1)

# 开始拖动验证码图片

# 模拟鼠标按下左键（开始拖动）
pyautogui.mouseDown(button='left')

# 1°代表多少像素
distance = 0.48

distance = distance * angle_deg
pyautogui.moveRel(distance, 0, duration=0.5)

# 模拟鼠标释放左键（结束拖动）
pyautogui.mouseUp(button='left')

# # 等待页面加载完成
time.sleep(120)

# 关闭浏览器
# driver.quit()
